
function twoSum(arr, target) {
    let result = [];
    let temp = [];
    let dep = 0;
    function dfs(temp, target, dep) {
        if (target == 0) {
            result.push(temp)
            return
        }
        for (let i = dep; i < arr.length; i++) {
            if (target < arr[i]) break
            temp.push(arr[i])
            dfs(temp.slice(), target - arr[i], i)
            temp.pop()
        }
    }
    dfs(temp, target, dep)
    return result
}

// console.log(twoSum([1,2,1],3))

console.log(twoSum([2, 3, 6, 7], 7))
console.log(twoSum([2,3,5],8))
console.log(twoSum( [2],1))
console.log(twoSum([1],1))

// candidates = [2], target = 1
// 输出: []
// 示例 4：

// 输入: candidates = [1], target = 1
// 输出: [[1]]
// 示例 5：

// 输入: candidates = [1], target = 2
// 输出: [[1,1]]